package com.jinzhu.controller;

import com.jinzhu.pojo.*;
import com.jinzhu.service.ClazzService;
import com.jinzhu.service.StuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/students")
public class StuController {
    @Autowired
    private StuService stuService;
    @Autowired
    private ClazzService clazzService;

    @GetMapping
    public Result AllStu1(@RequestParam (required = false) String name,
                          @RequestParam(required = false) Integer degree,
                          @RequestParam(required = false)Integer clazzId,
                          @DateTimeFormat(pattern = "yyyy-MM-dd") Integer begin,
                          @DateTimeFormat(pattern = "yyyy-MM-dd") Integer end,
                          @RequestParam(defaultValue = "1") Integer StuPage,
                          @RequestParam(defaultValue = "10") Integer StuPageSize) {

        log.info("AllStu 获取分页数据");
        return Result.success(stuService.AllStu1(name, degree, clazzId,begin, end, StuPage, StuPageSize));

    }

    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable Integer[] ids) {
        log.info("delete 批量删除学员信息数据");
        return  stuService.delete(ids)>0?Result.success():Result.error();
    }

    @PostMapping
    public Result add(@RequestBody Student student) {
        log.info("add 添加学员信息数据");
        return Result.success(stuService.add(student)>0?Result.success():Result.error());

    }

    @GetMapping("/{id}")
    public Result get(@PathVariable Integer id) {
        log.info("get 获取学员信息数据");
        Student student = stuService.get(id);
        return student == null?Result.error("没有该学生"):Result.success(student);
    }

    @PutMapping
    public Result update(@RequestBody Student student) {
        log.info("update 修改学员信息数据");
        if (student==null||student.getId()==null){
            return Result.error("学员ID不能为空");
        }
        return stuService.update(student)>0?Result.success():Result.error("修改失败");
    }

    @PutMapping("/violation/{id}/{score}")
    public Result violation(@PathVariable Integer id, @PathVariable Integer score) {
        log.info("violation 根据学员Id进行违纪信息数据");

        return stuService.violation(id, score)>0?Result.success():Result.error();
    }

//    @GetMapping("/report/empGenderData")
//    public Result empGenderData() {
//        log.info("empGenderData 获取员工性别数据");
//        List<GenderCount> empGenderData = stuService.empGenderData();
//        return Result.success(empGenderData);
//    }
//
//    @GetMapping("/report/empJobData")
//    public Result empJobData() {
//        log.info("empJobData 统计各职位员工数据");
//        List<JobCount> empJobData = stuService.empJobData();
//        return Result.success(empJobData);
//
//
//    }
//    @GetMapping("/report/studentDegreeData")
//    public Result studentDegreeData() {
//        log.info("studentDegreeData 统计各学历学生数据");
//        List<StudentCount> studentDegreeData = stuService.studentDegreeData();
//        return Result.success(studentDegreeData);
//
//    }
//    @GetMapping("/report/studentCountData")
//    public Result studentCountData() {
//        log.info("studentCountData 统计每一个班级的人数");
//        List<StudentCount> studentCountData = clazzService.studentCountData();
//        return Result.success(studentCountData);
//    }








}
